package fe.pong.tennis.input;

import flash.display.Sprite;
import flash.geom.Point;

class InputTouch implements InputConfiguration {

	private var _input: InputManager;
	private var _destino: Point;

	public function new(input: InputManager) {
		_input = input;
		_destino = null;
	}

	public function getShoot(): Point {
		return _input.getGesto();
	}

	public function getMove(): Point {
		return _destino;
	}

	public function isSooting(objeto: Sprite): Bool {
		return _input.isMoving() && isIn(_input.getPosicion(), objeto);
	}

	public function isMoving(objeto: Sprite): Bool {
		if (_input.isPressing()) {
			_destino = _input.getPosicion().add(_input.getGesto());
		}
		if (_destino == null)
			return false;
		return !isIn(_destino, objeto);
	}

	private static function isIn(point: Point, area: Sprite) {
		return
			point.x > area.x &&
			point.x < area.x + area.width &&
			point.y > area.y &&
			point.y < area.y + area.height;
	}

}